package com.liu.QQ.server.service;

import java.util.HashMap;
import java.util.Iterator;

/**
 * 管理和客户端通信的线程
 *
 * @author liuchengjie
 */
public class ManageServerThread {

    private static HashMap<String, ServerConnectThread> manage = new HashMap<>();

    public static void addConnectThread(String userId, ServerConnectThread connectThread) {
        manage.put(userId, connectThread);
    }

    public static ServerConnectThread getConnectThread(String userId) {
        return manage.get(userId);
    }
    /**
     * 返回在线用户列表
     */
    public static String getOnlineUserList() {
        Iterator<String> iterator = manage.keySet().iterator();
        String onlineUserList = "";
        while (iterator.hasNext()) {
            onlineUserList += iterator.next().toString()+" ";
        }
        return onlineUserList;
    }
    /**
     * 从集合中移除某个线程对象
     */
    public static void removeThread(String userId) {
        manage.remove(userId);
    }

    public static HashMap<String, ServerConnectThread> getManage() {
        return manage;
    }
}
